/*
 * Copyright (C) 2020 FoilPlanet
 *
 */

#ifndef _ANBOX_CODEC_SERVER_H_
#define _ANBOX_CODEC_SERVER_H_

#include "anbox/runtime.h"
#include "anbox/codec/client_info.h"
#include "anbox/network/socket_messenger.h"
#include "anbox/network/socket_connection.h"
#include "anbox/platform/base_platform.h"

#include <atomic>

namespace anbox {

namespace network {
class PublishedSocketConnector;
} // namespace network

namespace codec {
class Server {
 public:
  Server(const std::shared_ptr<Runtime>& rt, const std::shared_ptr<platform::BasePlatform> &platform);
  ~Server();

  std::string socket_file() const { return socket_file_; }

 private:
  void create_connection_for(std::shared_ptr<boost::asio::basic_stream_socket<
                             boost::asio::local::stream_protocol>> const& socket);

  int next_id();

  std::shared_ptr<platform::BasePlatform> platform_;
  const std::shared_ptr<Runtime> runtime_;
  std::string socket_file_;
  std::shared_ptr<network::PublishedSocketConnector> connector_;
  std::shared_ptr<network::Connections<network::SocketConnection>> const connections_;
  std::atomic<int> next_id_;
};
} // namespace codec
} // namespace anbox

#endif /* _ANBOX_CODEC_SERVER_H_ */
